GIT 变基
基
- 说明
* 02f7168 (HEAD, master) add autorestart
| * 8138be4 (hotfix) bug fix
|/
……………………
………….
…….
..
以上为分支。需要把补丁变基到02f7168 之后使提交记录更简洁。
- 首先checkout hotfix 分支上
[book@SERVER realsync]$ git co hotfix
Switched to branch 'hotfix'
把hotfix 变基到master 之后。使master成为hotfix 的父提交。
但发现master 分支未和hotfix 合并
[book@SERVER realsync]$ git rebase master
* 7a377fe (HEAD, hotfix) bug fix
* 02f7168 (master) add autorestart
……………………
………….
…….
..
- 合并master分支
Checkout master 分支
[book@SERVER realsync]$ git co master
Switched to branch 'master'
[book@SERVER realsync]$ git merge hotfix
最后变基完成。
1.1. 变基例子:
如果先要把modify的修改应用到master 分支上。 因为hotfix 分支还不稳定。
- 先把client 的C8 ,C9 合并到master 目标分之上。
git rebase --onto master modify hotfix
合并后图示
- 合并master 分支。
[book@SERVER scripts_new]$ git co master
Switched to branch 'master'
[book@SERVER scripts_new]$ git merge hotfix
修改后示意图:
1.2. 如果需要把server 分支变基合并:
前面分支为master 分支,后边分支为需要变基的分支。
git rebase [basebranch] [topicbranch]
git rebase master modify
变基之后的图片:
示意图:
- 推进master 分支:
[book@SERVER scripts_new]$ git co master
Switched to branch 'master'
[book@SERVER scripts_new]$ git merge modify
图示:
- 删除不必要的分支:
[book@SERVER scripts_new]$ git br -d hotfix modify
变基完成
1.3. 变基注意事项:
-
如果仓库外有副本,则不能变基操作:
-
遇到以上问题需要使用 git pull --rebase
配置文件:
git config --global pull.rebase true